from Base import Base
from selenium.webdriver.common.by import By
import time

class Page(Base):
    login_loc = (By.CSS_SELECTOR,'.headerLogin')
    def login(self):
        self.click(self.login_loc)

    name_loc = (By.ID,'userName')
    def name(self,username):
        self.send_keys(self.name_loc,username)

    pwd_loc = (By.NAME,'_pwd')
    def pwd(self,password):
        self.send_keys(self.pwd_loc,password)

    loginbtn_loc = (By.ID,'save')
    def loginbtn(self):
        self.click(self.loginbtn_loc)

    sure_loc = (By.XPATH,'//a[@href="https://www.jiuxian.com/"]')
    def sure(self):
        self.click(self.sure_loc)

    def luoji_01(self,username,password):
        try:
            self.open_url('https://www.jiuxian.com/')
            self.driver.implicitly_wait(10)
            self.login()
            self.name(username)
            self.pwd(password)
            time.sleep(15)
            self.loginbtn()
            self.sure()
            time.sleep(3)
        except Exception as e:
            t = time.strftime('%Y%m%d%H%M%S')
            self.driver.save_screenshot(t + '.png')
            print(e)